<!DOCTYPE html>
<html lang="en-us">
    <head><meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1'><meta name='description' content='数据集 数据集采用latex
. ├── formula_images_processed ├── im2latex_formulas.norm.lst ├── im2latex_test_filter.lst ├── im2latex_train_filter.lst ├── im2latex_validate_filter.lst ├── readme.txt ├── test.pkl ├── train.pkl └── validate.pkl formula_images_processed: 文件夹存储了10&#43;万张公式图片 im2latex_formulas.norm.lst: 图片对应的latex数学公式 im2latex_test_filter.lst: 测试集（图片：标签） im2latex_train_filter.lst: 训练集 im2latex_validate_filter.lst: 验证集 test.pkl: 测试集读取模型 train.pkl: 训练集读取模型 validate.pkl: 验证集读取模型
创建vocab from os.path import join import pickle as pkl from collections import Counter import argparse START_TOKEN = 0 PAD_TOKEN = 1 END_TOKEN = 2 UNK_TOKEN = 3 # 创建标签类别 &amp;#34;&amp;#34;&amp;#34;args sign2id: (sign: id) ex:(&amp;#39;\\delta&amp;#39;: 56) id2sign: (id: sign) length: 统计符号个数 &amp;#34;&amp;#34;&amp;#34; class Vocab(object): def __init__(self): self.'><title>基于深度学习的公式识别</title>

<link rel='canonical' href='https://enrique518.gitee.io/p/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A003/'>

<link rel="stylesheet" href="/scss/style.min.css"><meta property='og:title' content='基于深度学习的公式识别'>
<meta property='og:description' content='数据集 数据集采用latex
. ├── formula_images_processed ├── im2latex_formulas.norm.lst ├── im2latex_test_filter.lst ├── im2latex_train_filter.lst ├── im2latex_validate_filter.lst ├── readme.txt ├── test.pkl ├── train.pkl └── validate.pkl formula_images_processed: 文件夹存储了10&#43;万张公式图片 im2latex_formulas.norm.lst: 图片对应的latex数学公式 im2latex_test_filter.lst: 测试集（图片：标签） im2latex_train_filter.lst: 训练集 im2latex_validate_filter.lst: 验证集 test.pkl: 测试集读取模型 train.pkl: 训练集读取模型 validate.pkl: 验证集读取模型
创建vocab from os.path import join import pickle as pkl from collections import Counter import argparse START_TOKEN = 0 PAD_TOKEN = 1 END_TOKEN = 2 UNK_TOKEN = 3 # 创建标签类别 &amp;#34;&amp;#34;&amp;#34;args sign2id: (sign: id) ex:(&amp;#39;\\delta&amp;#39;: 56) id2sign: (id: sign) length: 统计符号个数 &amp;#34;&amp;#34;&amp;#34; class Vocab(object): def __init__(self): self.'>
<meta property='og:url' content='https://enrique518.gitee.io/p/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A003/'>
<meta property='og:site_name' content='Enriqueliu'>
<meta property='og:type' content='article'><meta property='article:section' content='Post' /><meta property='article:published_time' content='2021-11-19T00:00:00&#43;00:00'/><meta property='article:modified_time' content='2021-11-19T00:00:00&#43;00:00'/>
<meta name="twitter:title" content="基于深度学习的公式识别">
<meta name="twitter:description" content="数据集 数据集采用latex
. ├── formula_images_processed ├── im2latex_formulas.norm.lst ├── im2latex_test_filter.lst ├── im2latex_train_filter.lst ├── im2latex_validate_filter.lst ├── readme.txt ├── test.pkl ├── train.pkl └── validate.pkl formula_images_processed: 文件夹存储了10&#43;万张公式图片 im2latex_formulas.norm.lst: 图片对应的latex数学公式 im2latex_test_filter.lst: 测试集（图片：标签） im2latex_train_filter.lst: 训练集 im2latex_validate_filter.lst: 验证集 test.pkl: 测试集读取模型 train.pkl: 训练集读取模型 validate.pkl: 验证集读取模型
创建vocab from os.path import join import pickle as pkl from collections import Counter import argparse START_TOKEN = 0 PAD_TOKEN = 1 END_TOKEN = 2 UNK_TOKEN = 3 # 创建标签类别 &amp;#34;&amp;#34;&amp;#34;args sign2id: (sign: id) ex:(&amp;#39;\\delta&amp;#39;: 56) id2sign: (id: sign) length: 统计符号个数 &amp;#34;&amp;#34;&amp;#34; class Vocab(object): def __init__(self): self.">
    </head>
    <body class="
    article-page has-toc
">
    <script>
        (function() {
            const colorSchemeKey = 'StackColorScheme';
            if(!localStorage.getItem(colorSchemeKey)){
                localStorage.setItem(colorSchemeKey, "auto");
            }
        })();
    </script><script>
    (function() {
        const colorSchemeKey = 'StackColorScheme';
        const colorSchemeItem = localStorage.getItem(colorSchemeKey);
        const supportDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches === true;

        if (colorSchemeItem == 'dark' || colorSchemeItem === 'auto' && supportDarkMode) {
            

            document.documentElement.dataset.scheme = 'dark';
        } else {
            document.documentElement.dataset.scheme = 'light';
        }
    })();
</script>
<div class="container main-container flex 
    
        extended
    
">
    
        <div id="article-toolbar">
            <a href="https://enrique518.gitee.io/" class="back-home">
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-chevron-left" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <polyline points="15 6 9 12 15 18" />
</svg>



                <span>返回</span>
            </a>
        </div>
    
<main class="main full-width">
    <article class="main-article">
    <header class="article-header">

    <div class="article-details">
    
    <header class="article-category">
        
            <a href="/categories/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/" >
                机器学习
            </a>
        
    </header>
    

    <h2 class="article-title">
        <a href="/p/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A003/">基于深度学习的公式识别</a>
    </h2>

    

    
    <footer class="article-time">
        
            <div>
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-calendar-time" width="56" height="56" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <path d="M11.795 21h-6.795a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2h12a2 2 0 0 1 2 2v4" />
  <circle cx="18" cy="18" r="4" />
  <path d="M15 3v4" />
  <path d="M7 3v4" />
  <path d="M3 11h16" />
  <path d="M18 16.496v1.504l1 1" />
</svg>
                <time class="article-time--published">Nov 19, 2021</time>
            </div>
        

        
            <div>
                <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-clock" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="12" cy="12" r="9" />
  <polyline points="12 7 12 12 15 15" />
</svg>



                <time class="article-time--reading">
                    阅读时长: 2 分钟
                </time>
            </div>
        
    </footer>
    
</div>
</header>

    <section class="article-content">
    <h2 id="数据集">数据集</h2>
<p>数据集采用latex</p>
<pre><code>.
├── formula_images_processed
├── im2latex_formulas.norm.lst
├── im2latex_test_filter.lst
├── im2latex_train_filter.lst
├── im2latex_validate_filter.lst
├── readme.txt
├── test.pkl
├── train.pkl
└── validate.pkl
</code></pre><p><strong>formula_images_processed:</strong> 文件夹存储了10+万张公式图片
<strong>im2latex_formulas.norm.lst:</strong> 图片对应的latex数学公式
<strong>im2latex_test_filter.lst:</strong> 测试集（图片：标签）
<strong>im2latex_train_filter.lst:</strong> 训练集
<strong>im2latex_validate_filter.lst:</strong> 验证集
<strong>test.pkl:</strong> 测试集读取模型
<strong>train.pkl:</strong> 训练集读取模型
<strong>validate.pkl:</strong> 验证集读取模型</p>
<h2 id="创建vocab">创建vocab</h2>
<div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"><span class="kn">from</span> <span class="nn">os.path</span> <span class="kn">import</span> <span class="n">join</span>
<span class="kn">import</span> <span class="nn">pickle</span> <span class="kn">as</span> <span class="nn">pkl</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">Counter</span>
<span class="kn">import</span> <span class="nn">argparse</span>

<span class="n">START_TOKEN</span> <span class="o">=</span> <span class="mi">0</span>
<span class="n">PAD_TOKEN</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">END_TOKEN</span> <span class="o">=</span> <span class="mi">2</span>
<span class="n">UNK_TOKEN</span> <span class="o">=</span> <span class="mi">3</span>

<span class="c1"># 创建标签类别</span>
<span class="s2">&#34;&#34;&#34;args
</span><span class="s2">sign2id: (sign: id) ex:(&#39;</span><span class="se">\\</span><span class="s2">delta&#39;: 56)
</span><span class="s2">id2sign: (id: sign)
</span><span class="s2">length: 统计符号个数
</span><span class="s2">&#34;&#34;&#34;</span>
<span class="k">class</span> <span class="nc">Vocab</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sign2id</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&#34;&lt;s&gt;&#34;</span><span class="p">:</span> <span class="n">START_TOKEN</span><span class="p">,</span> <span class="s2">&#34;&lt;/s&gt;&#34;</span><span class="p">:</span> <span class="n">END_TOKEN</span><span class="p">,</span>
                        <span class="s2">&#34;&lt;pad&gt;&#34;</span><span class="p">:</span> <span class="n">PAD_TOKEN</span><span class="p">,</span> <span class="s2">&#34;&lt;unk&gt;&#34;</span><span class="p">:</span> <span class="n">UNK_TOKEN</span><span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">id2sign</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">((</span><span class="n">idx</span><span class="p">,</span> <span class="n">token</span><span class="p">)</span>
                            <span class="k">for</span> <span class="n">token</span><span class="p">,</span> <span class="n">idx</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sign2id</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">length</span> <span class="o">=</span> <span class="mi">4</span>

    <span class="k">def</span> <span class="nf">add_sign</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sign</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">sign</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sign2id</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">sign2id</span><span class="p">[</span><span class="n">sign</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">length</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">id2sign</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">length</span><span class="p">]</span> <span class="o">=</span> <span class="n">sign</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">length</span> <span class="o">+=</span> <span class="mi">1</span>

    <span class="k">def</span> <span class="fm">__len__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">length</span>

    <span class="k">def</span> <span class="fm">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="s2">&#34;Vocabulary ((n = {})&#34;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sign2id</span><span class="p">))</span>
</code></pre></div><h2 id="heading"></h2>
<div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"><span class="n">min_count</span> <span class="o">=</span> <span class="mi">10</span>
<span class="n">vocab</span> <span class="o">=</span> <span class="n">Vocab</span><span class="p">()</span>
<span class="n">counter</span> <span class="o">=</span> <span class="n">Counter</span><span class="p">()</span>

<span class="n">data_dir</span> <span class="o">=</span> <span class="s2">&#34;data&#34;</span>
<span class="n">formulas_file</span> <span class="o">=</span> <span class="n">join</span><span class="p">(</span><span class="n">data_dir</span><span class="p">,</span> <span class="s1">&#39;im2latex_formulas.norm.lst&#39;</span><span class="p">)</span>
<span class="c1"># 读取latex公式文件，每一个标签（公式）存储于列表formulas</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">formulas_file</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
    <span class="n">formulas</span> <span class="o">=</span> <span class="p">[</span><span class="n">formula</span><span class="o">.</span><span class="n">strip</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span> <span class="k">for</span> <span class="n">formula</span> <span class="ow">in</span> <span class="n">f</span><span class="o">.</span><span class="n">readlines</span><span class="p">()]</span>

<span class="c1"># 读取训练集</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">join</span><span class="p">(</span><span class="n">data_dir</span><span class="p">,</span> <span class="s1">&#39;im2latex_train_filter.lst&#39;</span><span class="p">),</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
    <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
        <span class="n">_</span><span class="p">,</span> <span class="n">idx</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">strip</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
        <span class="n">idx</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">idx</span><span class="p">)</span>
        <span class="n">formula</span> <span class="o">=</span> <span class="n">formulas</span><span class="p">[</span><span class="n">idx</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
        <span class="c1"># 统计每个latex符号出现的次数</span>
        <span class="n">counter</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">formula</span><span class="p">)</span>

    <span class="k">for</span> <span class="n">word</span><span class="p">,</span> <span class="n">count</span> <span class="ow">in</span> <span class="n">counter</span><span class="o">.</span><span class="n">most_common</span><span class="p">():</span>
        <span class="k">if</span> <span class="n">count</span> <span class="o">&gt;=</span> <span class="n">min_count</span><span class="p">:</span>
            <span class="n">vocab</span><span class="o">.</span><span class="n">add_sign</span><span class="p">(</span><span class="n">word</span><span class="p">)</span>
</code></pre></div><h2 id="引包">引包</h2>
<div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"><span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">partial</span>

<span class="kn">import</span> <span class="nn">torch</span>
<span class="kn">import</span> <span class="nn">torch.optim</span> <span class="kn">as</span> <span class="nn">optim</span>
<span class="kn">from</span> <span class="nn">torch.utils.data</span> <span class="kn">import</span> <span class="n">DataLoader</span>
<span class="kn">from</span> <span class="nn">torch.optim.lr_scheduler</span> <span class="kn">import</span> <span class="n">ReduceLROnPlateau</span>

<span class="kn">from</span> <span class="nn">model</span> <span class="kn">import</span> <span class="n">Im2LatexModel</span><span class="p">,</span> <span class="n">Trainer</span>
<span class="kn">from</span> <span class="nn">utils1</span> <span class="kn">import</span> <span class="n">collate_fn</span>
<span class="kn">from</span> <span class="nn">data</span> <span class="kn">import</span> <span class="n">Im2LatexDataset</span>
</code></pre></div><h2 id="读取数据集">读取数据集</h2>
<div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"><span class="n">batch_size</span> <span class="o">=</span> <span class="mi">32</span>
<span class="n">max_len</span> <span class="o">=</span> <span class="mi">150</span>
<span class="n">use_cuda</span> <span class="o">=</span> <span class="bp">False</span>
<span class="n">data_path</span> <span class="o">=</span> <span class="s2">&#34;data/&#34;</span>

<span class="n">train_loader</span> <span class="o">=</span> <span class="n">DataLoader</span><span class="p">(</span>
    <span class="n">Im2LatexDataset</span><span class="p">(</span><span class="n">data_path</span><span class="p">,</span> <span class="s1">&#39;train&#39;</span><span class="p">,</span> <span class="n">max_len</span><span class="p">),</span>
    <span class="n">batch_size</span><span class="o">=</span><span class="n">batch_size</span><span class="p">,</span>
    <span class="c1"># partial将值vocab.sign2id赋予函数collate_fn第一个参数</span>
    <span class="n">collate_fn</span><span class="o">=</span><span class="n">partial</span><span class="p">(</span><span class="n">collate_fn</span><span class="p">,</span> <span class="n">vocab</span><span class="o">.</span><span class="n">sign2id</span><span class="p">),</span>
    <span class="n">pin_memory</span><span class="o">=</span><span class="bp">True</span> <span class="k">if</span> <span class="n">use_cuda</span> <span class="k">else</span> <span class="bp">False</span><span class="p">,</span>
    <span class="n">num_workers</span><span class="o">=</span><span class="mi">4</span>
<span class="p">)</span>
</code></pre></div><h3 id="检查数据集示例">检查数据集示例</h3>
<div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"><span class="n">sample</span> <span class="o">=</span> <span class="nb">next</span><span class="p">(</span><span class="nb">iter</span><span class="p">(</span><span class="n">train_loader</span><span class="p">))</span>
</code></pre></div><p>sample[0]为32个3通道32x128的图片，sample[1]为图片对应的32个标签</p>
<div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"><span class="n">sample</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span> <span class="n">sample</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">shape</span>

<span class="p">(</span><span class="n">torch</span><span class="o">.</span><span class="n">Size</span><span class="p">([</span><span class="mi">32</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">32</span><span class="p">,</span> <span class="mi">128</span><span class="p">]),</span> <span class="n">torch</span><span class="o">.</span><span class="n">Size</span><span class="p">([</span><span class="mi">32</span><span class="p">,</span> <span class="mi">42</span><span class="p">]))</span>
</code></pre></div><p>显示图片</p>
<div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"><span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="kn">as</span> <span class="nn">plt</span>
<span class="o">%</span><span class="n">matplotlib</span> <span class="n">inline</span>

<span class="n">plt</span><span class="o">.</span><span class="n">imshow</span><span class="p">(</span><span class="n">sample</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="p">:,</span> <span class="p">:],</span> <span class="n">cmap</span><span class="o">=</span><span class="s2">&#34;gray&#34;</span><span class="p">)</span>
</code></pre></div><p>&lt;matplotlib.image.AxesImage at 0x7fd74844f850&gt;
<figure 
	>
	<a href="/1.png" >
		<img src="/1.png"
			
			
			
			loading="lazy"
			>
	</a>
	
</figure></p>
<p>根据latex符号表打印标签</p>
<div class="highlight"><pre class="chroma"><code class="language-python" data-lang="python"><span class="k">print</span><span class="p">([</span><span class="n">vocab</span><span class="o">.</span><span class="n">id2sign</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">e</span><span class="p">)]</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">sample</span><span class="p">[</span><span class="mi">1</span><span class="p">][</span><span class="mi">1</span><span class="p">]])</span>

<span class="p">[</span><span class="s1">&#39;&lt;s&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;Z&#39;</span><span class="p">,</span> <span class="s1">&#39;(&#39;</span><span class="p">,</span> <span class="s1">&#39;{&#39;</span><span class="p">,</span> <span class="s1">&#39;j&#39;</span><span class="p">,</span> <span class="s1">&#39;_&#39;</span><span class="p">,</span> <span class="s1">&#39;{&#39;</span><span class="p">,</span> <span class="s1">&#39;k&#39;</span><span class="p">,</span> <span class="s1">&#39;}&#39;</span><span class="p">,</span> <span class="s1">&#39;}&#39;</span><span class="p">,</span> <span class="s1">&#39;)&#39;</span><span class="p">,</span> <span class="s1">&#39;=&#39;</span><span class="p">,</span> <span class="s1">&#39;e&#39;</span><span class="p">,</span> <span class="s1">&#39;^&#39;</span><span class="p">,</span> <span class="s1">&#39;{&#39;</span><span class="p">,</span> <span class="s1">&#39;i&#39;</span><span class="p">,</span> <span class="s1">&#39;Z&#39;</span><span class="p">,</span> <span class="s1">&#39;_&#39;</span><span class="p">,</span> <span class="s1">&#39;{&#39;</span><span class="p">,</span> <span class="s1">&#39;c&#39;</span><span class="p">,</span> <span class="s1">&#39;}&#39;</span><span class="p">,</span> <span class="s1">&#39;(&#39;</span><span class="p">,</span> <span class="s1">&#39;{&#39;</span><span class="p">,</span> <span class="s1">&#39;j&#39;</span><span class="p">,</span> <span class="s1">&#39;_&#39;</span><span class="p">,</span> <span class="s1">&#39;{&#39;</span><span class="p">,</span> <span class="s1">&#39;k&#39;</span><span class="p">,</span> <span class="s1">&#39;}&#39;</span><span class="p">,</span> <span class="s1">&#39;}&#39;</span><span class="p">,</span> <span class="s1">&#39;)&#39;</span><span class="p">,</span> <span class="s1">&#39;}&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;pad&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;pad&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;pad&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;pad&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;pad&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;pad&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;pad&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;pad&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;pad&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;pad&gt;&#39;</span><span class="p">,</span> <span class="s1">&#39;&lt;pad&gt;&#39;</span><span class="p">]</span>
</code></pre></div>
</section>


    <footer class="article-footer">
    

    
    <section class="article-copyright">
        <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-copyright" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <circle cx="12" cy="12" r="9" />
  <path d="M14.5 9a3.5 4 0 1 0 0 6" />
</svg>



        <span>Licensed under CC BY-NC-SA 4.0</span>
    </section>
    </footer>


    
        <link 
                rel="stylesheet" 
                href="https://cdn.jsdelivr.net/npm/katex@0.13.13/dist/katex.min.css"integrity="sha384-RZU/ijkSsFbcmivfdRBQDtwuwVqK7GMOw6IMvKyeWL2K5UAlyp6WonmB8m7Jd0Hn"crossorigin="anonymous"
            ><script 
                src="https://cdn.jsdelivr.net/npm/katex@0.13.13/dist/katex.min.js"integrity="sha384-pK1WpvzWVBQiP0/GjnvRxV4mOb0oxFuyRxJlk6vVw146n3egcN5C925NCP7a7BY8"crossorigin="anonymous"
                defer="true"
                >
            </script><script 
                src="https://cdn.jsdelivr.net/npm/katex@0.13.13/dist/contrib/auto-render.min.js"integrity="sha384-vZTG03m&#43;2yp6N6BNi5iM4rW4oIwk5DfcNdFfxkk9ZWpDriOkXX8voJBFrAO7MpVl"crossorigin="anonymous"
                defer="true"
                >
            </script><script>
    window.addEventListener("DOMContentLoaded", () => {
        renderMathInElement(document.querySelector(`.article-content`), {
            delimiters: [
                { left: "$$", right: "$$", display: true },
                { left: "$", right: "$", display: false },
                { left: "\\(", right: "\\)", display: false },
                { left: "\\[", right: "\\]", display: true }
            ]
        });})
</script>
    
</article>

    <aside class="related-contents--wrapper">
    
    
        <h2 class="section-title">相关文章</h2>
        <div class="related-contents">
            <div class="flex article-list--tile">
                
                    
<article class="">
    <a href="/p/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A004/">
        
        

        <div class="article-details">
            <h2 class="article-title">文献综述</h2>
        </div>
    </a>
</article>
                
                    
<article class="">
    <a href="/p/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A002/">
        
        

        <div class="article-details">
            <h2 class="article-title">机器学习篇章之Kaggle比赛（预测房价）</h2>
        </div>
    </a>
</article>
                
                    
<article class="">
    <a href="/p/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A001/">
        
        

        <div class="article-details">
            <h2 class="article-title">机器学习篇章之感知机</h2>
        </div>
    </a>
</article>
                
                    
<article class="">
    <a href="/p/%E6%9C%BA%E5%99%A8%E5%AD%A6%E4%B9%A0/">
        
        

        <div class="article-details">
            <h2 class="article-title">机器学习篇章之线性回归</h2>
        </div>
    </a>
</article>
                
            </div>
        </div>
    
</aside>

     
     
        
    <div class="disqus-container">
    <div id="disqus_thread"></div>
<script type="application/javascript">
    var disqus_config = function () {
    
    
    
    };
    (function() {
        if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
            document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
            return;
        }
        var d = document, s = d.createElement('script'); s.async = true;
        s.src = '//' + "hugo-theme-stack" + '.disqus.com/embed.js';
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>

<style>
    .disqus-container {
        background-color: var(--card-background);
        border-radius: var(--card-border-radius);
        box-shadow: var(--shadow-l1);
        padding: var(--card-padding);
    }
</style>

<script>
    window.addEventListener('onColorSchemeChange', (e) => {
        if (DISQUS) {
            DISQUS.reset({
                reload: true
            });
        }
    })
</script>

    

    <footer class="site-footer">
    <section class="copyright">
        &copy; 
        
            2020 - 
        
        2022 Enriqueliu
    </section>
    
    <section class="powerby">
        Built with <a href="https://gohugo.io/" target="_blank" rel="noopener">Hugo</a> <br />
        Theme <b><a href="https://github.com/CaiJimmy/hugo-theme-stack" target="_blank" rel="noopener" data-version="3.2.0">Stack</a></b> designed by <a href="https://jimmycai.com" target="_blank" rel="noopener">Jimmy</a>
    </section>
</footer>


    
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    
    <div class="pswp__bg"></div>

    
    <div class="pswp__scroll-wrap">

        
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                
                
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div><script 
                src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"integrity="sha256-ePwmChbbvXbsO02lbM3HoHbSHTHFAeChekF1xKJdleo="crossorigin="anonymous"
                defer="true"
                >
            </script><script 
                src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"integrity="sha256-UKkzOn/w1mBxRmLLGrSeyB4e1xbrp4xylgAWb3M42pU="crossorigin="anonymous"
                defer="true"
                >
            </script><link 
                rel="stylesheet" 
                href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.css"integrity="sha256-c0uckgykQ9v5k&#43;IqViZOZKc47Jn7KQil4/MP3ySA3F8="crossorigin="anonymous"
            ><link 
                rel="stylesheet" 
                href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.css"integrity="sha256-SBLU4vv6CA6lHsZ1XyTdhyjJxCjPif/TRkjnsyGAGnE="crossorigin="anonymous"
            >

            </main>
    
        <aside class="sidebar right-sidebar sticky">
            <section class="widget archives">
                <div class="widget-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-hash" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
  <path stroke="none" d="M0 0h24v24H0z"/>
  <line x1="5" y1="9" x2="19" y2="9" />
  <line x1="5" y1="15" x2="19" y2="15" />
  <line x1="11" y1="4" x2="7" y2="20" />
  <line x1="17" y1="4" x2="13" y2="20" />
</svg>



                </div>
                <h2 class="widget-title section-title">目录</h2>
                
                <div class="widget--toc">
                    <nav id="TableOfContents">
  <ol>
    <li><a href="#数据集">数据集</a></li>
    <li><a href="#创建vocab">创建vocab</a></li>
    <li><a href="#heading"></a></li>
    <li><a href="#引包">引包</a></li>
    <li><a href="#读取数据集">读取数据集</a>
      <ol>
        <li><a href="#检查数据集示例">检查数据集示例</a></li>
      </ol>
    </li>
  </ol>
</nav>
                </div>
            </section>
        </aside>
    

        </div>
        <script 
                src="https://cdn.jsdelivr.net/npm/node-vibrant@3.1.5/dist/vibrant.min.js"integrity="sha256-5NovOZc4iwiAWTYIFiIM7DxKUXKWvpVEuMEPLzcm5/g="crossorigin="anonymous"
                defer="false"
                >
            </script><script type="text/javascript" src="/ts/main.js" defer></script>
<script>
    (function () {
        const customFont = document.createElement('link');
        customFont.href = "https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700&display=swap";

        customFont.type = "text/css";
        customFont.rel = "stylesheet";

        document.head.appendChild(customFont);
    }());
</script>

    </body>
</html>
